from wtforms import Form
from wtforms.fields import StringField, PasswordField, IntegerField
from wtforms.validators import DataRequired, Email, Length, EqualTo, ValidationError
import re
from .base_validate import ValidateMixin


class BaseAddressValidate(Form, ValidateMixin):
    name = StringField(validators=[DataRequired(message='name不能为空'), Length(min=1, max=10)])
    mobile = StringField(validators=[DataRequired(message='mobile不能为空')])
    province = StringField(validators=[DataRequired(message='province不能为空'), Length(min=1, max=50, message='省份名过长')])
    city = StringField(validators=[DataRequired(message='city不能为空'), Length(min=1, max=50, message='城市名字过长')])
    country = StringField(validators=[DataRequired(message='country不能为空'), Length(min=1, max=50, message='国家名过长')])
    detail = StringField(validators=[DataRequired(message='detail不能为空'), Length(min=1, max=100, message='地址详情长度过长')], )

    def validate_mobile(self, field):
        self.check_mobile(field)


class AddressPostValidate(BaseAddressValidate):
    pass


class AddressPutValidate(BaseAddressValidate):
    id = IntegerField(validators=[DataRequired(message='address的id不能为空或者非整数')])


class AddressDeleteValidate(Form):
    id = IntegerField(validators=[DataRequired(message='address的id不能为空或者非整数')])
